﻿
using System;
using Common.Logging;
using InDbContext;
using Newtonsoft.Json;

namespace In.Api.Helpers
{
    public static class HospWsLogHelper
    {
        private static readonly ILog Logger = LogManager.GetLogger(typeof(HospWsLogHelper));

        public static void Log(string type, string request, string response)
        {
            try
            {
                //写日志
                using (var ctx = new HospDatabaseEntity())
                {
                    var log = new Log
                    {
                        Action = type,
                        Request = request,
                        Response = response,
                        CreateDT = DateTime.Now
                    };
                    ctx.Logs.Add(log);
                    ctx.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("Log表保存出错{0}",JsonConvert.SerializeObject(ex));
            }
        }
    }
}